/**
 * Kien hang
 */
package model.entity;

import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;

import model.Constant;

/**
 * @author heroandtn3
 * 
 */
public class Pieces {
	private final int PADDING = Constant.PADDING;
	private final int BOX_SIZE = Constant.BOX_SIZE;
	private final int CELL_SIZE = BOX_SIZE + 2*PADDING;

	private int x, y, row, col; // toa do theo x, y va hang, cot
	private int saveX, saveY; // toa do x, y luu tru
	private int speed; // toc do
	private int toX, toY; // huong di chuyen
	private Image shape; // hinh dang
	private int delay; // delay time in miliseconds
	private int type; // loai

	/**
	 * 
	 */
	public Pieces(int type, String urlID) {
		// TODO Auto-generated constructor stub
		this.type = type;
		this.shape = new ImageIcon(Constant.PIE_DIR + urlID + "/" + type).getImage();
		this.speed = 3;
		this.toX = 0;
		this.toY = 1;
		this.saveX = this.x = Constant.SEND_COL*CELL_SIZE;
		this.saveY = this.y = Constant.SEND_ROW*CELL_SIZE;
	}

	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}

	/**
	 * @param x
	 *            the x to set
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

	/**
	 * @param y
	 *            the y to set
	 */
	public void setY(int y) {
		this.y = y;
	}

	/**
	 * @return the row
	 */
	public int getRow() {
		return row;
	}

	/**
	 * @param row
	 *            the row to set
	 */
	public void setRow(int row) {
		this.row = row;
	}

	/**
	 * @return the col
	 */
	public int getCol() {
		return col;
	}

	/**
	 * @param col
	 *            the col to set
	 */
	public void setCol(int col) {
		this.col = col;
	}

	/**
	 * @return the speed
	 */
	public int getSpeed() {
		return speed;
	}

	/**
	 * @param speed
	 *            the speed to set
	 */
	public void setSpeed(int speed) {
		this.speed = speed;
	}

	/**
	 * @return the toX
	 */
	public int getToX() {
		return toX;
	}

	/**
	 * @param toX
	 *            the toX to set
	 */
	public void setToX(int toX) {
		this.toX = toX;
	}

	/**
	 * @return the toY
	 */
	public int getToY() {
		return toY;
	}

	/**
	 * @param toY
	 *            the toY to set
	 */
	public void setToY(int toY) {
		this.toY = toY;
	}

	/**
	 * @return the shape
	 */
	public Image getShape() {
		return shape;
	}

	/**
	 * @param shape
	 *            the shape to set
	 */
	public void setShape(Image shape) {
		this.shape = shape;
	}

	/**
	 * @return the delay
	 */
	public int getDelay() {
		return delay;
	}

	/**
	 * @param delay the delay to set
	 */
	public void setDelay(int delay) {
		this.delay = delay;
	}

	/**
	 * @return the saveX
	 */
	public int getSaveX() {
		return saveX;
	}

	/**
	 * @param saveX the saveX to set
	 */
	public void setSaveX(int saveX) {
		this.saveX = saveX;
	}

	/**
	 * @return the saveY
	 */
	public int getSaveY() {
		return saveY;
	}

	/**
	 * @param saveY the saveY to set
	 */
	public void setSaveY(int saveY) {
		this.saveY = saveY;
	}


	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	// di chuyen theo toa do
	public void move() {
		saveX = x;
		saveY = y;
		x += toX * speed;
		y += toY * speed;
	}
	
	// doi huong khi gap mui ten
	public void redirected(int typeArrow) {
		switch (typeArrow) {
		case 1:
			// di len
			toX = 0;
			toY = -1;
			break;
		case 2:
			// di sang phai
			toX = 1;
			toY = 0;
			break;
		case 4:
			// di xuong duoi
			toX = 0;
			toY = 1;
			break;
		case 8:
			// di sang trai
			toX = -1;
			toY = 0;
			break;
		}
	}
	
	// paint itseft
	public void paint(Graphics2D g2d) {
		g2d.drawImage(shape, x, y, BOX_SIZE, BOX_SIZE, null);
	}

}
